package jedes;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import redis.clients.jedis.Jedis;

import java.util.concurrent.TimeUnit;

public class RedisDemo {
    public static void main(String[] args) {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:16379");

        RedissonClient redisson = Redisson.create(config);

        RLock lock = redisson.getLock("lock");

        lock.lock(10, TimeUnit.SECONDS);

        Jedis db = new Jedis("tcp://127.0.0.1:16379");
        System.out.println(db.ping());

        db.set("key", "value");
        System.out.println(db.get("key"));

        //异步锁
        db.setnx("key1", "value");

    }

}
